package com.j2eefast.bussiness.contract.service;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.j2eefast.bussiness.contract.entity.BusArchivesEntity;
import com.j2eefast.bussiness.contract.entity.BusScrapEntity;
import com.j2eefast.bussiness.contract.mapper.BusArchivesMapper;
import com.j2eefast.bussiness.contract.mapper.BusScrapMapper;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.framework.annotation.DataFilter;
import com.j2eefast.framework.sys.entity.SysUserEntity;
import com.j2eefast.framework.utils.Constant;
import com.j2eefast.framework.utils.UserUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * <p>设备档案</p>
 *
 * @author: summer
 * @date: 2021-06-08 14:41
 * @web: http://www.letukeji.cn
 * @version: 1.0.1
 */

@Service
public class BusArchivesService extends ServiceImpl<BusArchivesMapper, BusArchivesEntity> {

    @Resource
    protected BusArchivesMapper busArchivesMapper;


    /**
     * 页面分页查询
     */
    public PageUtil findPage(Map<String, Object> params) {
        QueryWrapper<BusArchivesEntity> r = new QueryWrapper<BusArchivesEntity>();
        String equipmentCode = (String) params.get("equipmentCode");
        String equipmentCode2 = (String) params.get("equipmentCode2");
        String equipmentName = (String) params.get("equipmentName");
        String equipmentName2 = (String) params.get("equipmentName2");
        String equipmentModel = (String) params.get("equipmentModel");
        String meteringUnit = (String) params.get("meteringUnit");

        Page<BusArchivesEntity> page = busArchivesMapper.findPage(new Query<BusArchivesEntity>(params).getPage(),
                StrUtil.nullToDefault(equipmentCode, ""),
                StrUtil.nullToDefault(equipmentCode2, ""),
                StrUtil.nullToDefault(equipmentName, ""),
                StrUtil.nullToDefault(equipmentName2, ""),
                StrUtil.nullToDefault(equipmentModel, ""),
                StrUtil.nullToDefault(meteringUnit, "")
        );
        return new PageUtil(page);
    }

    public List<BusArchivesEntity> findList(Map<String, Object> params) {
        QueryWrapper<BusArchivesEntity> r = new QueryWrapper<BusArchivesEntity>();
        String userCode = (String) params.get("userCode");
        String meteringUnit = (String) params.get("meteringUnit");
//项目名称
        String projectName = (String) params.get("projectName");
        List<BusArchivesEntity> page = busArchivesMapper.findList(new Query<BusArchivesEntity>(params).getPage(),
                StrUtil.nullToDefault(userCode, ""),
                StrUtil.nullToDefault(meteringUnit, ""),
                StrUtil.nullToDefault(projectName, "")
        );
        return page;
    }


    public boolean deleteByIds(Long[] ids) {

        return busArchivesMapper.deleteByIds(ids);

    }

    public boolean updateCheck(Long id) {
        Long userId = UserUtils.getUserInfo().getId();

        return busArchivesMapper.updateCheck(id, userId);

    }

    public SysUserEntity getSysById(@Param("userId") Long userId) {
        return busArchivesMapper.getSysById(userId);
    }







//    public PageUtil findPage(Map<String, Object> params) {
//        QueryWrapper<BusArchivesEntity> r = new QueryWrapper<BusArchivesEntity>();
//        String a = (String) params.get("userCode");
//        String b = (String) params.get("meteringUnit");
//        String c = (String) params.get("equipmentType");
//        Page<BusArchivesEntity> page = this.baseMapper.selectPage(new Query<BusArchivesEntity>(params).getPage(), r);
//        return new PageUtil(page);
//    }

//    /**
//     * 页面展示查询翻页
//     */
//    public PageUtil findPage(Map<String, Object> params) {
//
//		//String parentId = (String) params.get("parentId");
//        Page<BusScrapEntity> page = busScrapMapper.findPage(
//                new Query<BusDepreciationEntity>(params).getPage(),
//				//StrUtil.nullToDefault(parentId,""),
//                (String) params.get(Constant.SQL_FILTER));
//        return new PageUtil(page);
//    }

//    @DataFilter(compAlias = "c", deptAlias = "d", userAlias = "u")
//    public List<BusArchivesEntity> findList(Map<String, Object> params) {
////        String name = (String) params.get("name");
////        String ceoName = (String) params.get("ceoName");
////        String paymentNuit = (String) params.get("paymentNuit");
////        String contractSum = (String) params.get("contractSum");
////        String projectName = (String) params.get("projectName");
//        Long[] ids = (Long[]) params.get("ids");
//        return busArchivesMapper.findList(
////                StrUtil.nullToDefault(name,""),
////                StrUtil.nullToDefault(ceoName,""),
////                StrUtil.nullToDefault(paymentNuit,""),
////                StrUtil.nullToDefault(projectName,""),
////                StrUtil.nullToDefault(contractSum,""),
//                ids,
//                (String) params.get(Constant.SQL_FILTER));
//    }




//    public int getDepreciationInfo(String name){
//
//        BusDepreciationEntity b= busDepreciationMapper.getDepreciationInfo(name);
//        if(b!=null){
//            return 1;
//        }else
//            return 0;
//
//    }







}
